import VueRouter from 'vue-router'
import Vue from 'vue'
Vue.use(VueRouter)

const routes=[
    {
        name: 'index',
        path: '/',
        component: () => import('../views/home/index'),
        meta:{
            title:'中国近代图书全文数据库'
        }
    },{
        name: 'main',
        path: '/main',
        redirect:'/categorySearch',
        component: () => import('../components/layout/layout'),
        children:[
            {
                name: 'categorySearch',
                path: '/categorySearch',
                component: () => import('../views/categorySearch/index'),
                meta:{
                    title:'中国近代图书全文数据库',
                    pageName:'书目检索'
                }
            },
            {
                name: 'moreSearch',
                path: '/moreSearch',
                component: () => import('../views/moreSearch/index'),
                meta:{
                    title:'中国近代图书全文数据库',
                    pageName:'高级检索'
                }
            },
            {
                name: 'moreVersion',
                path: '/moreVersion/:id',
                component: () => import('../views/moreVersion/index'),
                meta:{
                    title:'中国近代图书全文数据库',
                    pageName:'更多版本'
                }
            },
            {
                name: 'detail',
                path: '/detail/:id',
                component: () => import('../views/detail/index'),
                meta:{
                    title:'中国近代图书全文数据库',
                    pageName:'详情'
                }
            },
            {
                name: 'mapSearch',
                path: '/mapSearch',
                component: () => import('../views/mapSearch/index'),
                meta:{
                    title:'中国近代图书全文数据库',
                    pageName:'地图搜索'
                }
            }
        ]
    }
]

const router=new VueRouter({
    routes
})

router.beforeEach((to,from,next)=>{
    if(to.meta.title)document.title=to.meta.title
    next()
})

export default router
